
//% color="#FFC1C1" iconWidth=50 iconHeight=40
namespace XYXKCASR{

    //% block="Initialize Alibaba Cloud real-time speech recognition token[TOKEN]appkey[APPKEY]" blockType="command"
    //% TOKEN.shadow="String" TOKEN.defl="token"
    //% APPKEY.shadow="String" APPKEY.defl="appkey"
      export function asrInit(parameter: any, block: any) {
        let token = parameter.TOKEN.code
        let appkey = parameter.APPKEY.code
        Generator.addInclude('XYXKC_ASR_Include', '#include <XYXKC_ASR.h>');
        Generator.addObject('XYXKC_ASR_Object', 'XYXKC_ASR',`xyxkc_asr;`);
        Generator.addSetup(`XYXKC_ASR_Setup`,`xyxkc_asr.asrInit(${token},${appkey});`)

      }
    //% block="enable real time speech recognition" blockType="command"
    export function enableSpeechRecognition(parameter: any, block: any) {
        Generator.addCode(`xyxkc_asr.enableSpeechRecognition();`)
    }
    //% block="disable real time speech recognition" blockType="command"
    export function stopSpeechRecognition(parameter: any, block: any) {
        let topic = parameter.TOPIC.code
        Generator.addCode(`xyxkc_asr.stopSpeechRecognition();`)
    }



    //% block="speech recognition successful?" blockType="boolean"
    export function isIdentificationSuccessful(parameter: any, block: any) {
        Generator.addCode(`(xyxkc_asr.isIdentificationSuccessful())`)
    }

    //% block="obtain speech recognition results" blockType="reporter"
    export function getAsrResult(parameter: any, block: any) {
        Generator.addCode(`(xyxkc_asr.getAsrResult())`)
    }

    //% block="initialize the universal open ai interface api url[URL] appkey[APPKEY] model[MODEL]" blockType="command"
    //% URL.shadow="String" URL.defl="apiUrl"
    //% APPKEY.shadow="String" APPKEY.defl="appkey"
    //% MODEL.shadow="String" MODEL.defl="model"
    export function openAiInit(parameter: any, block: any) {
        let url = parameter.URL.code
        let appkey = parameter.APPKEY.code
        let model = parameter.MODEL.code
        Generator.addInclude('XYXKC_openAi_Include', '#include <XYXKC_openAi.h>');
        Generator.addObject('XYXKC_openAi_Object', 'XYXKC_openAi',`XYXKC_openAi;`);
        Generator.addSetup(`XYXKC_openAi_Setup_Begin`,`XYXKC_openAi.openAiBegin(${url},${appkey},${model});`)

    }
    //% block="Initialize the big model role (system) as[SYSTEM]" blockType="command"
    //% SYSTEM.shadow="String" SYSTEM.defl="system"
    export function setRole(parameter: any, block: any) {
        let system = parameter.SYSTEM.code
        Generator.addInclude('XYXKC_openAi_Include', '#include <XYXKC_openAi.h>');
        Generator.addObject('XYXKC_openAi_Object', 'XYXKC_openAi',`XYXKC_openAi;`);
        Generator.addSetup(`XYXKC_openAi_Setup_ROle`,`XYXKC_openAi.setRole(${system});`);
    }

    //% block="ask a question to the big model[TXT]" blockType="reporter"
    //% TXT.shadow="String" TXT.defl="What's your name?"
    export function getGPTAnswer(parameter: any, block: any) {
        let txt = parameter.TXT.code
        Generator.addCode(`(XYXKC_openAi.getGPTAnswer(${txt}))`)
    }
}